#!/usr/bin/perl

=head1 NAME

 dust-lib.pl - A library for dust

 Copyright (C) 2007 Paul Schulz <paul@mawsonlakes.org>

=head1 SYNOPSIS

  This is a library file for 'dust'. Portions were copied from
  'apt-cacher'.

  Portions of code taken, and modified from from Higher-Order Perl by
  Mark Dominus, published by Morgan Kaufmann Publishers, Copyright
  2005 by Elsevier Inc

=cut

# This function reads the given config file into the
# given hash ref. The key and value are separated by
# a '=' and will have all the leading and trailing 
# spaces removed.
sub read_config
{
    # set the default config variables
    my %config = (
		  store_dir => '/var/cache/dust/store',
		  store_type => 'SHA1-simple',
		  refs_dir => '/var/cache/dust/refs',
		  log_dir => '/var/log/dust',
		  admin_email => 'root@localhost',
		  );
    
    ($config_file) = @_;
    
    open CONFIG, $config_file or die $!;
    
    read(CONFIG, $buf, 50000);
    $buf=~s/\\\n#/\n#/mg; # fix broken multilines
    $buf=~s/\\\n//mg; # merge multilines
    
    for(split(/\n/, $buf))
    {
	# weed out whole comment lines immediately
	if(/^\#/) {
	}else{
	    s/#.*//;   # kill off comments
	    s/^\s+//;	# kill off leading spaces
	    s/\s+$//;	# kill off trailing spaces
	    
	    if ($_) {
		# split into key and value pair
		my ($key, $value) = split(/\s*=\s*/);
		$value = 0 unless ($value);
		#print "key: $key, value: $value\n";
		$config{$key} = $value;
		#print "$config{$key}\n";
	    }
		
	} 
    }

    close CONFIG;
    return \%config;
}
	

######### HOOKS ###########
#
# arg: file to be scanned and added to DB
sub import_sums {
   return 1;
}

# purpose: ?create?, lock the DB file and establish DB connection
sub db_init {
   return 1;
}

# purpose: create hasher object
sub data_init {
   return 1;
}

# purpose: append data to be scanned
sub data_feed {
   return 1;
}

# args: filename only or filename and sum
sub check_sum {
   return 1;
}

# args: filename and sum
sub store_sum {
}

1;
